package IO流复习;

import java.io.*;
import java.net.Socket;

class ObjectOutput_TCP {
    public static void main(String[] args) throws IOException {
        /*ObjectOutputStream outputStream=new ObjectOutputStream(new FileOutputStream("D:\\idea2022\\day.com.qiezi\\day_13\\src\\IO流复习\\students.txt"));
        students s1=new students();
        s1.setName("张三");
        s1.setAge(58);
        s1.setSex("男");
        s1.setMajor("老年大学");
        s1.setId("10086");
        students s2=new students();
        s2.setName("张四");
        s2.setAge(48);
        s2.setSex("女");
        s2.setMajor("老年大学");
        s2.setId("10087");
        students s3=new students();
        s3.setName("张五");
        s3.setAge(68);
        s3.setSex("女");
        s3.setMajor("老年大学");
        s3.setId("10088");
        outputStream.writeObject(s1);
        outputStream.writeObject(s2);
        outputStream.writeObject(s3);
        outputStream.close();*/
        //使用TCP创建客户端
        Socket socket=new Socket("127.0.0.1",1003);
        //读取本地文件
        BufferedInputStream bf=new BufferedInputStream(new FileInputStream("D:\\idea2022\\day.com.qiezi\\day_13\\src\\IO流复习\\students.txt"));
        BufferedOutputStream buf1=new BufferedOutputStream(socket.getOutputStream());
        byte[] bytes=new byte[5];
        int len;
        while ((len=bf.read(bytes))!=-1){
            buf1.write(bytes,0,len);
        }
        socket.shutdownOutput();
        socket.close();
    }
}
class students implements Serializable {
    private static final long serialVersionUID=42222L;
    private String name;
    private int age;
    private String sex;
    private String major;
    private String id;

    public students() {
    }

    public students(String name, int age, String sex, String major, String id) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.major = major;
        this.id = id;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return sex
     */
    public String getSex() {
        return sex;
    }

    /**
     * 设置
     * @param sex
     */
    public void setSex(String sex) {
        this.sex = sex;
    }

    /**
     * 获取
     * @return major
     */
    public String getMajor() {
        return major;
    }

    /**
     * 设置
     * @param major
     */
    public void setMajor(String major) {
        this.major = major;
    }

    /**
     * 获取
     * @return id
     */
    public String getId() {
        return id;
    }

    /**
     * 设置
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    public String toString() {
        return "students{name = " + name + ", age = " + age + ", sex = " + sex + ", major = " + major + ", id = " + id + "}";
    }
}
